#!/usr/bin/python
# -*-coding:utf-8-*-
# pip install ddddocr 图片识别
"""农产品质量追溯管理平台"""
import math
import time
import re
import requests
import json
from bs4 import BeautifulSoup
from time import sleep
import common
import db
from datetime import datetime
from dotenv import load_dotenv, find_dotenv
import os
import asyncio
from pyppeteer import launch
import numpy as np
import pandas as pd
import os

mysqldb = db.DbManager()

load_dotenv(verbose=True)
# 今天
today_time = common.TodayTime()
# 将-替换为.
today_time_new = today_time.replace('-', '.')
# 账号
username = os.getenv('LOGIN_ADMIN')
passworld = os.getenv('LOGIN_PWD')

async def login():
    cookie_str = "JSESSIONID=DB7D45F5BA7B93C16DCCCC73C9E2A517; __jsluid_h=da33a1581a524f4bb24d0b27e03afa05"
    cookies = {cookies.split('=')[0]: cookies.split('=')[-1] for cookies in cookie_str.split('; ')}
    data = {
        'callback':'jQuery17205162399788358172_1669893318537',
        'startrecord':1,
        'endrecord':5,
        'perpage':5,
        'columnId':'8e55b8c5-a4a3-42c5-b009-07750502304a',
        '_':1669965726005,
    }
    headers = {
        'Referer': 'http://fgw.lyg.gov.cn/lygsfzhggwyh/jgxq/jgxq.html',
        'User-Agent': 'apifox/1.0.0 (https://www.apifox.cn)',
    }
    resp = requests.get(
        "http://fgw.lyg.gov.cn/TrueCMS/messageController/getMessage.do?callback=jQuery17205162399788358172_1669893318537&startrecord=1&endrecord=5&perpage=5&contentTemplate=&columnId=8e55b8c5-a4a3-42c5-b009-07750502304a&_=1669965726005",
        headers=headers, cookies=cookies)  # , cookies=cookies, data=data
    txt=resp.text
    href=re.split("href='",txt)
    with open(os.getcwd()+"/link.txt", 'w') as file:
        for i in range(0,len(href)):
            if i>0:
                link=re.split("\'",href[i])
                print(link)
                file.write(link[0]+"\n")
    exit()

class Egas:
    def __init__(self):
        self.url = "http://zs.jsncpaq.com/"
        self.main()

    def main(self):
        # 登录
        asyncio.get_event_loop().run_until_complete(login())

Egas()
